package com.lanqiao.gxnushop.mapper;

import com.lanqiao.gxnushop.entity.Sellers;
import com.lanqiao.gxnushop.util.StringUtil;
import com.lanqiao.gxnushop.valueObject.SellerNeed;

public class SellersMapperProvide {
    public String getListString(Sellers sellers){
        StringBuffer sb = new StringBuffer("select  * from sellers where 1 = 1 ");
        if(StringUtil.isNotEmpty(sellers.getName()) && sellers.getName() != ""){
            sb.append(" and name like concat('%',#{name},'%')");
        }
        if(StringUtil.isNotEmpty(sellers.getState())&&sellers.getState() != ""){
            sb.append(" and state = #{state}");
        }
        String sql = sb.toString();
        return sql;
    }

    public String getOrderListString(SellerNeed sn){
        StringBuffer sb = new StringBuffer("select orders.orderId as orderId,\n" +
                "\t\t\tstores.sellerId as sellerId,\n" +
                "\t\t\tstores.storeId as storeId,\n" +
                "\t\t\tstores.name as storeName,\n" +
                "\t\t\tproducts.productId as productId,\n" +
                "\t\t\tproducts.name as productName,\n" +
                "\t\t\tproducts.price as price,\n" +
                "\t\t\tbuyers.buyerId as buyerId,\n" +
                "\t\t\tbuyers.name as buyerName,\n" +
                "\t\t\taddress.address as acceptAddress, \n" +
                "\t\t\taddress.phone as acceptPhone,\n" +
                "\t\t\taddress.name as acceptName,\n" +
                "\t\t\torders.zcsj as orderTime, \n" +
                "\t\t\torders.quantity as quantity, \n" +
                "\t\t\torders.totalAmount as totalAmount\t,\n" +
                "\t\t\torders.state as state\n" +
                "from buyers join address  on (buyers.buyerId = address.buyerId) join orders on (orders.addressId = address.addressId) JOIN products on (orders.productId = products.productId) join stores on (stores.storeId = products.storeId)\n" +
                "where stores.sellerId = #{sellerId} ");
        if(StringUtil.isNotEmpty(sn.getStoreId()) && sn.getStoreId()!=""){
            sb.append(" and stores.storeId = #{storeId}");
        }
        if(StringUtil.isNotEmpty(sn.getProductName())&&sn.getProductName()!=""){
            sb.append(" and products.Name like concat('%',#{productName},'%')");
        }
        if(StringUtil.isNotEmpty(sn.getState()) && sn.getState()!=""){
            sb.append(" and orders.state = #{state}");
        }
        if(StringUtil.isNotEmpty(sn.getStoreName()) && sn.getStoreName()!=""){
            sb.append(" and stores.name like concat('%',#{storeName},'%')");
        }
        String sql = sb.toString();
        return sql;
    }
}
